import socket


def client():
    port = 12345  # 这里先默认，可从配置文件读取更灵活
    client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_address = ('localhost', port)
    client_socket.connect(server_address)
    try:
        while True:
            message = input("Enter command: ")
            client_socket.send(message.encode())
            data = client_socket.recv(1024).decode()
            print(data)
    except KeyboardInterrupt:
        pass
    finally:
        client_socket.close()


if __name__ == "__main__":
    client()